/* v-permission 权限指令 */
import store from "@/store/index";

export default {
	inserted(el, binding) {
		const roles = store.getters.userRoles;
		if (binding.value && binding.value instanceof Array && binding.value.length > 0) {
			// 判断用户是否拥有该角色
			const res = roles.some(role => {
				return binding.value.includes(role);
			});
			!res && el.parentNode && el.parentNode.removeChild(el);
		}
	},
	// 实际中应该不需要update
	update(el, binding) {
		const roles = store.getters.userRoles;
		if (binding.value && binding.value instanceof Array && binding.value.length > 0) {
			// 判断用户是否拥有该角色
			const res = roles.some(role => {
				return binding.value.includes(role);
			});
			!res && el.parentNode && el.parentNode.removeChild(el);
		}
	},
};
